﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using Portal.Exam.Model;
using Portal.Exam.Bussiness;
using Portal.Web.Model;
using Portal.Web.Utility;
using Portal.Core;

namespace Portal.Exam.Render
{
    public class ExamCollectionTreeViewRenderBll
    {
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string RootExamCollectionId = (string)WebEnvironments.Request(SiteId, "RId");
                if (string.IsNullOrEmpty(RootExamCollectionId)) RootExamCollectionId = "";

              

                string Html =
                    "<script language=javascript>\r\n"+
                    "     function BackFromAddExamCollection()\r\n"+
                    "     {\r\n"+
                    "         document.getElementById('divFormAddExamCollection').innerHTML='';\r\n" +
                    "         document.getElementById('divFormAddExamCollection').style.display='none';\r\n" +
                    "         document.getElementById('divMainForm').style.display='block';\r\n" +
                    "     }\r\n"+
                    
                    "     function BackFromUpdateExamCollection()\r\n" +
                    "     {\r\n" +
                    "         document.getElementById('divFormUpdateExamCollection').innerHTML='';\r\n" +
                    "         document.getElementById('divFormUpdateExamCollection').style.display='none';\r\n" +
                    "         document.getElementById('divMainForm').style.display='block';\r\n" +
                    "     }\r\n" +

                    "     function AddTreeNode(id,title)\r\n"+
                    "     {\r\n"+
                    "           var SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "           var childNode=null;\r\n"+
                    "           if(SelectedNode!=null)\r\n"+
                    "           {\r\n"+
                    "               childNode = SelectedNode.addChild({\r\n"+
                    "                       isFolder: true\r\n"+
                    "               });\r\n"+
                    "               childNode.data.href=id;\r\n"+
                    "               childNode.setTitle(title);\r\n"+
                    "           }\r\n"+
                    "     }\r\n"+

                    "     function SaveTreeNode(id,title)\r\n" +
                    "     {\r\n"+
                    "          var SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "          SelectedNode.setTitle(title);\r\n" +
                    "     }\r\n"+


                    "     function ClientAddExamCollection(RId)\r\n" +
                    "     {\r\n" +
                    "         SiteId='"+SiteId+"';\r\n"+
                    "         ParentExamCollectionId=document.getElementById('txtSelectedExamCollectionId').value;\r\n" +
                    "         RootExamCollectionId='"+RootExamCollectionId+"';\r\n"+
                    "         AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideGetAddExamCollection(SiteId,RootExamCollectionId, ParentExamCollectionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         document.getElementById('divFormAddExamCollection').innerHTML=AjaxOut.HtmlContent;\r\n"+
                    "         document.getElementById('divFormAddExamCollection').style.display='block';\r\n"+
                    "         document.getElementById('divMainForm').style.display='none';\r\n" +
                    "     }\r\n" +

                    "     function ClientUpdateExamCollection(RId)\r\n" +
                    "     {\r\n" +
                    "         ExamCollectionId=document.getElementById('txtSelectedExamCollectionId').value;\r\n" +
                    "         AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideGetUpdateExamCollection(SiteId,ExamCollectionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         document.getElementById('divFormUpdateExamCollection').innerHTML=AjaxOut.HtmlContent;\r\n"+
                    "         document.getElementById('divFormUpdateExamCollection').style.display='block';\r\n" +
                    "         document.getElementById('divMainForm').style.display='none';\r\n" +
                    "     }\r\n" +



                    "     function ClientDeleteExamCollection(RId)\r\n" +
                    "     {\r\n" +
                    "         ExamCollectionId=document.getElementById('txtSelectedExamCollectionId').value;\r\n" +
                    "         if(ExamCollectionId=='')\r\n"+
                    "         {\r\n"+
                    "               alert('Chưa xác định thư mục cần xóa');\r\n"+
                    "               return;\r\n"+
                    "         }\r\n"+
                    "         if(ExamCollectionId==RId)\r\n" +
                    "         {\r\n" +
                    "               alert('Không xóa được thư mục gốc');\r\n" +
                    "               return;\r\n" +
                    "         }\r\n" +
                    "         if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n"+
                    "         AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideDeleteExamCollection(SiteId,ExamCollectionId).value;\r\n" +
                    "         if(AjaxOut.Error)\r\n" +
                    "         {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "         }\r\n" +
                    "         SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                    "         SelectedNode.remove();\r\n"+
                    "         tree.activateKey(RId);\r\n"+
                    "         ClientLoadQuestion(RId);\r\n"+
                    "     }\r\n" +


                    "   function ViewQuestion(ExamCollectionId,QuestionId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideViewQuestion(SiteId,ExamCollectionId,QuestionId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_self');\r\n" +
                    "   }\r\n" +

                    "   function RemoveQuestion(ExamCollectionId,QuestionId)\r\n" +
                    "   {\r\n" +
                    "       if(confirm('Bạn đã chắc chắn loại bỏ câu hỏi khỏi thư mục này chưa?')==false)return;\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       Keyword=document.getElementById('txtFilterKeyword').value;\r\n"+
                    "       AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideRemoveQuestionFromExamCollection(SiteId,ExamCollectionId,QuestionId, Keyword).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       document.getElementById('divQuestionList').innerHTML=AjaxOut.HtmlContent;\r\n" +
                    "   }\r\n" +
                    
                    
                    "   function SearchExamQuestion()\r\n"+
                    "   {\r\n"+
                    "         SiteId='"+SiteId+"';\r\n"+
                    "         ExamCollectionId=document.getElementById('txtSelectedExamCollectionId').value;\r\n" +
                    "         if(ExamCollectionId=='')\r\n" +
                    "         {\r\n" +
                    "               alert('Chưa xác định thư mục cần đưa câu hỏi vào');\r\n" +
                    "               return;\r\n" +
                    "         }\r\n" +
                    "       AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideGetSearchForm(SiteId,'"+RootExamCollectionId+"',ExamCollectionId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n"+
                    "       {\r\n"+
                    "           alert(AjaxOut.InfoMessage);\r\n"+
                    "           return;\r\n"+
                    "       }\r\n"+
                    "       document.getElementById('divSearchExamQuestion').innerHTML=AjaxOut.HtmlContent;\r\n"+
                    "       document.getElementById('divSearchExamQuestion').style.display='block';\r\n"+
                    "       document.getElementById('divMainForm').style.display='none';\r\n" +
                    "   }\r\n"+


                    "   function BackFromSearchExamQuestion()\r\n" +
                    "   {\r\n" +
                    "       document.getElementById('divSearchExamQuestion').innerHTML='';\r\n" +
                    "       document.getElementById('divSearchExamQuestion').style.display='none';\r\n" +
                    "       document.getElementById('divMainForm').style.display='block';\r\n" +
                    "   }\r\n" +
                    "</script>\r\n"+
                    ExamCollectionRenderBll.GetPlugInAddExamCollectionJavascript(SiteId,true)+
                    ExamCollectionRenderBll.GetPlugInUpdateExamCollectionJavascript(SiteId, true) +
                    SearchExamQuestion.GetPluginJavascript(SiteId)+

                    "<div id=divFormAddExamCollection></div>\r\n" +
                    "<div id=divFormUpdateExamCollection></div>\r\n" +
                    "<div id=divSearchExamQuestion></div>\r\n"+
                    "<div class=CssFormData id=divMainForm>\r\n" +
                        DrawFunction(SiteId, RootExamCollectionId).HtmlContent +
                    "<table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=col1><div class=CssDivExamCollection>" + DrawExamCollection(SiteId, RootExamCollectionId).HtmlContent + "</div></td>\r\n" +
                    "       <td class=col2>\r\n"+
                    "           <h3>Danh sách câu hỏi trong thư mục <div style=\"float:right\">Từ khóa: <input id=txtFilterKeyword style=\"margin-right:5px;\"><input type=button class=button value=\"Lọc dữ liệu\" onclick=\"javascript:ClientRefresh(0);\"></div></h3>\r\n"+
                    "           <div class=CssQuestionList id=\"divQuestionList\">" +
                                       ServerSideReadingQuestionInExamCollection(SiteId, RootExamCollectionId, "", 0).HtmlContent + "\r\n" +
                    "           </div>\r\n"+
                    "       </td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawExamCollection(string SiteId,string RootExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                ExamCollectionCls OExamCollection=ExamCollectionBll.CreateExamCollectionModel(SiteId,RootExamCollectionId);
                string Html =
                              "<script language=javascript>\r\n"+
                              "     function ClientLoadQuestion(ExamCollectionId)\r\n"+
                              "     {\r\n"+
                              "         SiteId='"+SiteId+"';\r\n"+
                              "         document.getElementById('txtSelectedExamCollectionId').value = ExamCollectionId;\r\n" +
                              "         Keyword=document.getElementById('txtFilterKeyword').value;\r\n" +
                              "         CurrentPageIndex=parseInt(document.getElementById('txtCurrentPageIndex').value);\r\n" +
                              "         AjaxOut = Portal.Exam.Render.ExamCollectionTreeViewRenderBll.ServerSideReadingQuestionInExamCollection(SiteId, ExamCollectionId, Keyword, CurrentPageIndex).value;\r\n" +
                              "         document.getElementById('divQuestionList').innerHTML=AjaxOut.HtmlContent;\r\n" +
                              "     }\r\n"+

                              "     function ClientRefresh(CurrentPageIndex)\r\n" +
                              "     {\r\n" +
                              "         SiteId='" + SiteId + "';\r\n" +
                              "         ExamCollectionId=document.getElementById('txtSelectedExamCollectionId').value;\r\n" +
                              "         document.getElementById('txtCurrentPageIndex').value=CurrentPageIndex;\r\n" +
                              "         ClientLoadQuestion(ExamCollectionId);\r\n" +
                              "     }\r\n" +
                              "</script>\r\n"+
                              "<input type=hidden id=\"txtSelectedExamCollectionId\" value=\"" + RootExamCollectionId + "\">\r\n" +
                              "<input type=hidden id=\"txtCurrentPageIndex\" value=\"0\">\r\n" +
                              "<h3><a href=\"QuestionInputDataTreeView.aspx\">" + OExamCollection.ExamCollectionName + "</a></h3>\r\n" +
                              "<div class=TreeHolder>\r\n"+
                              "<div id=\"tree\">\r\n"+
                              "<ul>\r\n"+
                              " <li class=\"folder expanded\"><a href=\"" + RootExamCollectionId + "\" target=\"_self\">" + OExamCollection.ExamCollectionName + "</a>\r\n" +
                              "     <ul>\r\n";
                ExamCollectionCls[] ExamCollections = ExamCollectionBll.ReadingExamCollection(SiteId, RootExamCollectionId);
                for (int iIndex = 0; iIndex < ExamCollections.Length; iIndex++)
                {
                    Html +=
                            "<li class=\"folder expanded\"><a href=\"" +  ExamCollections[iIndex].ExamCollectionId + "\" target=\"_self\">" + ExamCollections[iIndex].ExamCollectionName + "</a>\r\n" +
                                BuildSubTreeView(SiteId,ExamCollections[iIndex].ExamCollectionId).HtmlContent+
                            "</li>\r\n";
                }

                Html += "</ul>\r\n" +
                        "</li>\r\n"+
                        "</ul>\r\n"+
                        "</div>\r\n" +
                        "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut BuildSubTreeView(string SiteId,string ParentExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Html = "";
                ExamCollectionCls[] ExamCollections = ExamCollectionBll.ReadingExamCollection(SiteId, ParentExamCollectionId);
                Html+=
                    "<ul>\r\n";
                for (int iIndex = 0; iIndex < ExamCollections.Length; iIndex++)
                {
                    Html +=
                            "<li class=\"folder expanded\"><a target=\"_self\" href=\"" + ExamCollections[iIndex].ExamCollectionId + "\">" + ExamCollections[iIndex].ExamCollectionName + "</a>\r\n" +
                                BuildSubTreeView(SiteId,  ExamCollections[iIndex].ExamCollectionId).HtmlContent +
                            "</li>\r\n";
                }

                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawFunction(string SiteId,string RootExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);

                string Html =
                   "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:ClientAddExamCollection('" + RootExamCollectionId + "');\"><img class=image src=\""+IconRoot+"/Add.png\"><div>Tạo thư mục</div></li>\r\n" +
                   "            <li onclick=\"javascript:ClientDeleteExamCollection('" + RootExamCollectionId + "');\"><img class=image src=\""+IconRoot+"/Delete.png\"><div>Xóa thư mục</div></li>\r\n" +
                   "            <li onclick=\"javascript:ClientUpdateExamCollection('"+RootExamCollectionId+"');\"><img class=image src=\""+IconRoot+"/Update.png\"><div>Sửa thư mục</div></li>\r\n" +
                   "            <li onclick=\"javascript:ClientMoveExamCollection();\"><img class=image src=\""+IconRoot+"/Move.png\"><div>Chuyển thư mục</div></li>\r\n" +
                   //"            <li onclick=\"javascript:ClientAddQuestionData();\"><img class=image src=\"Resources/Images/AddQuestion.png\"><div>Thêm tài liệu</div></li>\r\n" +
                   "            <li onclick=\"javascript:SearchExamQuestion();\"><img class=image src=\""+IconRoot+"/selection.png\"><div>Chọn câu hỏi</div></li>\r\n" +
                   "            <li onclick=\"javascript:ClientRefresh(0);\"><img class=image src=\"" + IconRoot + "/Refresh.png\"><div>Đọc lại danh sách</div></li>\r\n" +
                   "            <li onclick=\"javascript:window.open('ExamCollection.aspx','_self');\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideReadingQuestionInExamCollection(
            string SiteId, 
            string ExamCollectionId,
            string Keyword,
            int CurrentPageIndex)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Html = "";
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);

                ExamCollectionCls OExamCollection = null;
                if (!string.IsNullOrEmpty(ExamCollectionId))
                {
                    OExamCollection = ExamCollectionBll.CreateExamCollectionModel(SiteId, ExamCollectionId);
                }
                
                if (OExamCollection != null)
                {
                    Html +=
                        "<h3>Đang chọn thư mục: " + OExamCollection.ExamCollectionName + "</h3>";
                }
                DataTable dtQuestion = ExamCollectionBll.ReadingQuestionForExamCollection(SiteId, ExamCollectionId, Keyword);
                if (dtQuestion.Rows.Count == 0)
                {
                    Html += "<div class=CssNoData>Không có câu hỏi nào thuộc bộ sưu tập</div>\r\n";
                }
                else
                {
                    ReturnPaging OReturnPaging = WebPaging.GetPaging(dtQuestion.Rows.Count, CurrentPageIndex, 25, 10, "ClientRefresh");
                    Html += 
                        OReturnPaging.PagingText+
                           "<div class=tabcontent id=divListQuestionResult>\r\n" +
                           "    <table>\r\n" +
                           "        <tr>\r\n" +
                           "            <th class=thIndex>#</th>\r\n" +
                           "            <th>Câu hỏi</th>\r\n" +
                           "            <th>Kiểu</th>\r\n" +
                           "            <th></th>\r\n" +
                           "            <th></th>\r\n" +
                           //"            <th></th>\r\n" +
                           //"            <th></th>\r\n" +
                           "        </tr>\r\n";
                    for (int iIndex = OReturnPaging.StartIndex; iIndex < OReturnPaging.EndIndex; iIndex++)
                    {
                        string QuestionId = (string)dtQuestion.Rows[iIndex]["QuestionId"];
                        string Type = (string)dtQuestion.Rows[iIndex]["Type"];
                        string Title = (string)dtQuestion.Rows[iIndex]["Title"];
                        Html+=
                           "        <tr>\r\n" +
                           "            <td class=tdIndex>"+(iIndex+1)+"</td>\r\n" +
                           "            <td><span class=CssQuestionSubject><a href=\"#\">" + Title + "</a></span></td>\r\n" +
                           "            <td>" + Type + "</td>\r\n" +
                           "            <td class=tdButton><a href=\"javascript:RemoveQuestion('" + ExamCollectionId + "','" + QuestionId + "');\"><img alt=\"Loại khỏi thư mục\" title=\"Loại khỏi thư mục\" class=imagebutton src=\"" + IconRoot + "/Remove.png\"></a></td>\r\n" +
                           //"            <td class=tdButton><a href=\"javascript:UpdateQuestion('" + ExamCollectionId + "','" + QuestionId + "');\"><img alt=\"Sửa thuộc tính tài liệu\" title=\"Sửa thuộc tính tài liệu\" class=imagebutton src=\"Resources/Images/Update.png\"></a></td>\r\n" +
                           "            <td class=tdButton><a href=\"javascript:ViewQuestion('" + ExamCollectionId + "','" + QuestionId + "');\"><img alt=\"Xem câu hỏi\" title=\"Xem câu hỏi\" class=imagebutton src=\""+IconRoot+"/preview.png\"></a></td>\r\n" +
                           //"            <td class=tdButton><a href=\"AddDataToExamCollection.aspx?ExamCollectionId=" + ExamCollectionId + "&QuestionId=" + QuestionId + "\"><img alt=\"Phân vào thư mục\" title=\"Phân vào thư mục\" class=imagebutton src=\"Resources/Images/Category.png\"></a></td>\r\n" +
                           "        </tr>\r\n";
                    }
                    Html += "</table>\r\n" +
                            "</div>\r\n";
                }
                OAjaxOut.HtmlContent = Html;
                    
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }





        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetAddExamCollection(
            string SiteId,
            string RootExamCollectionId,
            string ParentExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut =
                    ExamCollectionRenderBll.DrawAddExamCollectionForAjax(SiteId, RootExamCollectionId, ParentExamCollectionId, "javascript:BackFromAddExamCollection();");
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetUpdateExamCollection(
            string SiteId,
            string ExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut =
                    ExamCollectionRenderBll.DrawUpdateExamCollectionForAjax(SiteId, ExamCollectionId, "javascript:BackFromUpdateExamCollection();");
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }
        
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDeleteExamCollection(
            string SiteId,
            string ExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                ExamCollectionBll.DeleteExamCollection(SiteId, ExamCollectionId);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetSearchForm(
            string SiteId,
            string RootExamCollectionId,
            string ExamCollectionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut.HtmlContent = SearchExamQuestion.Draw(SiteId, ExamCollectionId).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideRemoveQuestionFromExamCollection(
            string SiteId,
            string ExamCollectionId,
            string QuestionId,
            string Keyword)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                ExamCollectionBll.RemoveCollectionFromExam(SiteId, ExamCollectionId, QuestionId);
                OAjaxOut.HtmlContent = ServerSideReadingQuestionInExamCollection(SiteId, ExamCollectionId, Keyword, 0).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideViewQuestion(
            string SiteId,
            string GroupQuestionId,
            string QuestionId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string UpdateUrl = "PreviewOneQuestion.aspx?QuestionId=" + QuestionId + "&RootGroupQuestionId=" + GroupQuestionId;
                OAjaxOut.RetUrl = UpdateUrl;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

    }
}
